package com.ewanghuiju.app.ui.my.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.SimpleActivity;
import com.ewanghuiju.app.model.bean.local.TabEntity;
import com.ewanghuiju.app.ui.main.adapter.MyPagerAdapter;
import com.ewanghuiju.app.ui.my.fragment.ShouyiListFragment;
import com.ewanghuiju.app.ui.watermail.activity.WaterOrderListActivity;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.List;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 收益列表
 * @time 2020/2/19
 */
public class ShouyiListActivity extends SimpleActivity {
    @BindView(R.id.viewpage)
    ViewPager viewpage;
    @BindView(R.id.xtabLayout)
    CommonTabLayout commonTabLayout;

    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;


//    private List<String> strList;
//
//    private String[] list_Title = {"收益明细", "收益提现"};

    private ArrayList<CustomTabEntity> mTabEntities;
    private List<String> titleList;

    private List<Fragment> fragmentList;

    @Override
    protected int getLayout() {
        return R.layout.activity_shouyi_list;
    }

    @Override
    protected void initEventAndData() {
        tvTitleRight.setTextColor(ContextCompat.getColor(mContext, R.color.color_666));
        initCommonTabLayoutAndFragment();
    }

    private void initCommonTabLayoutAndFragment() {

        fragmentList = new ArrayList<>();
        mTabEntities = new ArrayList<>();
        titleList = new ArrayList<>();
        titleList.add("收益明细");
        titleList.add("收益提现");
        mTabEntities.add(new TabEntity("收益明细", R.mipmap.icon_selected_tab, 0));
        mTabEntities.add(new TabEntity("收益提现", R.mipmap.icon_selected_tab, 0));

        for (int i = 0; i < titleList.size(); i++) {
            ShouyiListFragment shouyiListFragment = new ShouyiListFragment();
            Bundle bundle = new Bundle();
            bundle.putInt(Constants.SHOUYI_TYPE, i + 1);
            shouyiListFragment.setArguments(bundle);
            fragmentList.add(shouyiListFragment);
        }

        viewpage.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), 0, fragmentList, titleList));
        commonTabLayout.setTabData(mTabEntities);

        commonTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewpage.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {
            }
        });

        viewpage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                commonTabLayout.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        viewpage.setCurrentItem(0);
    }


    @Override
    protected int getTitleIntText() {
        return R.string.shouyi_details_title;
    }

    @Override
    protected void intSmartRefreshLayout() {
//        super.intSmartRefreshLayout();
    }

    @OnClick({R.id.tv_title_right})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.tv_title_right:
                //兑换记录
                new StartActivityUtil(mContext, WaterOrderListActivity.class).startActivity(true);
                break;
            default:
                break;
        }
    }


    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(mToolbar)
                .statusBarDarkFont(true)
                .init();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
